
import java.io.IOException;
import java.util.Scanner;



public class Start 
{
   public static void main (String[] args) throws IOException
   {
       /*double data[][] = 
       {
           {4,12,-16},{12,37,-43},{-16,-43,98}
       };*/
       
       /*double data[][] = 
       {
           {1,1,1,1},{1,7,5,5},{1,5,7,9},{1,5,9,18}
       };*/
       /*double dataA[][] = 
       {
           {-0.75,2,8.95},{-8.38,3.32,4.13},{8.69,2.47,-6.33}
       };*/
       double dataA[][] = 
       {
          {30,9,-1,10,-8,5,3},{8,85,7,1,5,4,-3},{-2,2,37,-5,3,8,7},{5,4,2,28,-5,0,1},{0,8,4,3,65,5,2},{4,-2,5,-1,2,54,3},{1,2,0,1,4,1,12}
       };
       double dataB[][] = 
       {
           {-2},{3},{-2},{1},{5},{4},{9}
       };
       /*double dataA[][] = 
       {
           {2,-1,1},{1,2,-1},{1,1,3}
       };
       double dataB[][] = 
       {
           {-2},{3},{-2}
       };*/
       
       Matrix a = new Matrix(dataA);
       Matrix b = new Matrix(dataB);

       System.out.println(a.toString()+"\n");
       System.out.println(b.toString()+"\n");
       Matrix res = a.gaussSeidel(b, 0.000001);
       System.out.println(res.toString()+"\n");


       //System.out.println(toto.toString()+"\n");
       /*Matrix test = new Matrix(data);
       Matrix res = test.choleskyDecomposition();
       System.out.println(test.toString()+"\n");
       System.out.println(res.toString()+"\n");*/
       /*Matrix a = new Matrix(12, 10);
       a.randomize(-5, 9);
       Matrix b = new Matrix(10, 5);
       b.randomize(-1, 9);
       Matrix res = a.multiply(b);
       System.out.println(a.toString()+"\n");
       System.out.println(b.toString()+"\n");
       System.out.println(res.toString()+"\n");*/
                /*Scanner sc = new Scanner(System.in);
                int nbLignes = 0;
                int nbColonnes = 0;
                double max = 0;
                double min = 0;
                Matrix principale = null;
                Matrix vecteur = null;
                Matrix x = null;
                
                System.out.println(" -----------------------");
                System.out.println("| Projet MAN - 14/03/13 |");
                System.out.println(" -----------------------");
	   	System.out.println("\nGroupe:\n- Antoine Ernewein\n- Magalie Gross\n- Etienne Heitz\n" );
                
                System.out.println("\n\nCreer une nouvelle matrice :");
                System.out.println("1- Aleatoire");
                System.out.println("2- Importer un fichier CSV");
                
                if (sc.nextInt() == 1)
                {
                    System.out.print("Nombre de lignes ? ");
                    nbLignes = sc.nextInt();
                    System.out.print("Nombre de colonnes ? ");
                    nbColonnes = sc.nextInt();
                    System.out.print("Valeur minimum ? ");
                    min = sc.nextDouble();
                    System.out.print("Valeur maximum ? ");
                    max = sc.nextDouble();
                    
                    principale = new Matrix(nbLignes, nbColonnes);
                    principale.randomize(min, max);
                }
                
                else 
                {
                    System.out.print("Chemin du fichier : ");
                    principale = Matrix.importCSV(sc.next());
                }
                
                boolean again = true;
                
                while (again)
                {
                   System.out.println("\nMatrice A :\n");
                   System.out.println(principale.toString());
                   System.out.println("Operations disponibles :\n");
                   System.out.println("1- Rendre triangulaire inferieure");
                   System.out.println("2- Rendre triangulaire superieure");
                   System.out.println("3- Resolution triangulaire inferieure");
                   System.out.println("4- Resolution triangulaire superieure");
                   System.out.println("5- Decomposition LU");
                   
                   switch (sc.nextInt())
                   {
                       case 1 :
                           principale.setLowerTriangular();
                           break;
                           
                       case 2 :
                           principale.setUpperTriangular();
                           break;
 
                       case 3 :
                           System.out.println("Definir vecteur b :\n");
                           vecteur = new Matrix(principale.nbLine, 1);
                           
                           for(int i = 0; i<principale.nbLine; i++)
                           {
                               System.out.println("Valeur indice " + i + " du vecteur :");
                               vecteur.setValue(i, 0, sc.nextDouble());
                           }
                           
                           x = Matrix.solveLowerTriangular(principale, vecteur);
                           System.out.println("\nVecteur solution x :");
                           System.out.println(x.toString());
                           System.out.println("\n<Entree> pour continuer");
                           sc.next();
                                   
                           break;
                           
                       case 4 :
                           System.out.println("Definir vecteur b :\n");
                           vecteur = new Matrix(principale.nbLine, 1);
                           
                           for (int i = 0; i < principale.nbLine; i++)
                           {
                               System.out.println("Valeur indice " + i + " du vecteur :");
                               vecteur.setValue(i, 0, sc.nextDouble());
                           }
                           
                           x = Matrix.solveUpperTriangular(principale, vecteur);
                           System.out.println("\nVecteur solution x :");
                           System.out.println(x.toString());
                           System.out.println("\n<Entree> pour continuer");
                           sc.next();
                                   
                           break;
                       
                        case 5 :
                           Matrix[] res = Matrix.LUDecomposition(principale);
                           System.out.println("\nVoulez vous :");
                           System.out.println("1- Exporter en csv");
                           System.out.println("2- Afficher le resultat");
                           int a = sc.nextInt();
                           if(a==2)
                           {
                            System.out.println("\nMatrice L :\n"+res[0].toString()+"\n");
                            System.out.println("Matrice U :\n"+res[1].toString()+"\n");
                           }
                           else{
                               res[0].exportCSV("MatriceL");
                               res[1].exportCSV("MatriceU");
                           }

                           System.out.println("\n<Entree> pour continuer");
                           sc.next();
                        break;    
                           
                       default:
                           break;
                   }
                   
                }*/
   }
}
